package com.example.home_app.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.home_app.R
import com.example.home_app.data.DataServer
import com.example.home_app.util.SbParameter
import com.example.home_app.util.Status
import com.example.home_app.util.ToastUtil.showToast
import java.util.*

/**
 * Created by dell on 2021/8/10.
 */


/**DataServer
 * 文 件 名: DriveHomeAdapter
 * 创 建 人: Allen
 * 创建日期: 16/12/24 15:33
 * 邮   箱: AllenCoder@126.com
 * 修改时间：
 * 修改备注：
 */

open class DriveHomeAdapter(var list: ArrayList<Map<String, Any>>) :
    BaseQuickAdapter<Status, BaseViewHolder>(
        R.layout.simple_adapter_item,
        DataServer.getSampleData(SbParameter.HomeSUM)
    ) {
    @SuppressLint("ResourceType")
    override fun convert(holder: BaseViewHolder, item: Status) {
        holder.setText(R.id.sai_id, list[holder.layoutPosition]["id"].toString())
        holder.setText(R.id.sai_name, list[holder.layoutPosition]["name"].toString())
        holder.setText(R.id.sai_phone, list[holder.layoutPosition]["online"].toString())

        if (list[holder.layoutPosition]["online"].toString() === "true") {
            holder.setTextColor(R.id.sai_phone,Color.GREEN)
        } else {
            holder.setTextColor(R.id.sai_phone,Color.RED)
        }
    }

    open fun Remove(position: Int) {
        list.removeAt(position)
        notifyItemRemoved(position)
    }

    private val clickableSpan: ClickableSpan = object : ClickableSpan() {
        override fun onClick(widget: View) {

            showToast("111")
            //showToast("事件触发了 landscapes and nedes")
        }

        override fun updateDrawState(ds: TextPaint) {
            ds.color = context.resources.getColor(R.color.clickspan_color)
            ds.isUnderlineText = true
        }
    }

//    private val clickableSpan: ClickableSpan = object : ClickableSpan() {
//        override fun onClick(widget: View) {}
//        override fun updateDrawState(ds: TextPaint) {
//            ds.color = context.resources.getColor(R.color.clickspan_color)
//            ds.isUnderlineText = true
//        }
//    }
}